package com.affablebeans.model.repository;

import java.sql.SQLException;
import java.util.List;

import javax.sql.DataSource;

import com.affablebeans.model.bll.DefaultTrueValidator;
import com.affablebeans.model.bll.GenericEntityBLL;
import com.affablebeans.model.dal.CustomerDAL;
import com.affablebeans.model.entity.Customer;

/**
 * 
 * @author Bora SAYINER
 * @since Jan 26, 2015 11:34:05 PM
 * @version 1.0.0
 */
public class Customers {

	private final GenericEntityBLL<Customer> customerBLL;

	public Customers(DataSource dataSource) {
		CustomerDAL customerDAL = new CustomerDAL(dataSource);
		DefaultTrueValidator<Customer> trueValidator = new DefaultTrueValidator<Customer>();
		this.customerBLL = new GenericEntityBLL<Customer>(customerDAL, trueValidator);
	}

	public boolean insertCustomer(Customer entity) throws SQLException {
		return customerBLL.insertEntity(entity);
	}

	public boolean updateCustomer(Customer entity) throws SQLException {
		return customerBLL.updateEntity(entity);
	}

	public boolean deleteCustomer(Customer entity) throws SQLException {
		return customerBLL.deleteEntity(entity);
	}

	public Customer findCustomerById(int id) throws SQLException {
		return customerBLL.findEntityById(id);
	}

	public List<Customer> getAllCustomers() throws SQLException {
		return customerBLL.getAllEntities();
	}

	public int getCount() throws SQLException {
		return customerBLL.getEntitiesCount();
	}
}
